package pancake.function;

 
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MyListFanItemView extends LinearLayout {
	private static final String TAG="MyListItemView";
	private Context context;
	private TextView txtName,txtMessage,txtDate,txtVia,txtID;
	private ImageView imageHeader;
 
	public MyListFanItemView(Context context,AttributeSet attrs)
	{
		super(context,attrs);
		initialize(context);
		
	}
	public MyListFanItemView(Context context)
	{
		super(context);
		initialize(context);
		
	}
	private void initialize(Context context)
	{
		 this.context  = context;
		 View view = LayoutInflater.from(this.context).inflate(R.layout.listitem,null);
		 this.txtName = (TextView)view.findViewById(R.id.txtName);
		 this.txtMessage = (TextView)view.findViewById(R.id.txtMessage);
		 this.txtDate = (TextView)view.findViewById(R.id.txtDate);
		 this.txtVia = (TextView)view.findViewById(R.id.txtVia);
		 this.txtID = (TextView)view.findViewById(R.id.txtID);
		 this.imageHeader = (ImageView)view.findViewById(R.id.imgTitle);
		 AddClickEvents(view,  this.context,this.txtName,this.txtMessage);
		 addView(view);
	}
	private void AddClickEvents(final View v,
								final Context mContext,
								final TextView txtName,
								final TextView txtMessage)
	{
		Button btnReply = (Button)v.findViewById(R.id.btnReply);
		Button btnFwd = (Button)v.findViewById(R.id.btnFwd);
		Button btnDM = (Button)v.findViewById(R.id.btnDirect);
		Button btnDel = (Button)v.findViewById(R.id.btnDel);
		
		btnReply.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				/*
				LayoutInflater inflater = LayoutInflater.from(mContext);
				View layout = inflater.inflate(R.layout.postmessage,null);
				EditText text = (EditText)layout.findViewById(R.id.txtInput);
				text.setText("@"+txtName.getText()+" ");
				*/
				MyPostMessageDialog cd = new MyPostMessageDialog(mContext);
				cd.show();
				cd.ReplyMessage(txtName.getText().toString(),txtMessage.getText().toString());
			}
			
		});
		
		
	}
	public void updateView(Data d)
	{
		this.txtName.setText(d.name);
		this.txtMessage.setText(d.message);
		this.txtDate.setText(d.date);
		this.txtVia.setText(d.via);
		this.txtID.setText(d.id);
		this.imageHeader.setImageResource(d.imgURLId);
		
	}
	public static final class Data
	{
		public String name;
		public String message;
		public String date;
		public String via;
		public String id;
		public int imgURLId;
		public Data(){}
		public Data(Data d)
		{
			name = d.name;
			message = d.message;
			date = d.date;
			via = d.via;
			id = d.id;
			imgURLId = d.imgURLId;
			
		}
	}
}
